function [stock_prices, stock_prices_ret_b, stock_prices_ret_s,...
    stock_dates_b, stock_dates_s, all_dates_ret_num,...
    all_ret_predicted_dup, all_ret_real_dup, all_dates_ret_num_b,...
    all_dates_ret_num_s, idx_buy, idx_sell, all_dates_p_l_num] = ...
    ...
    prepare_plot(all_dates_b, all_dates_s, all_dates_ret_num,...
    stock_id, all_dates_ret, all_ret_predicted, all_ret_real,...
    trades, cumu_p_l);


all_dates_buy_num = datenum(all_dates_b, 'yyyy-mm-dd');
all_dates_sell_num = datenum(all_dates_s, 'yyyy-mm-dd');

from_date = datestr(all_dates_ret_num(1), 'dd/mm/yyyy');
to_date = datestr(all_dates_ret_num(end), 'dd/mm/yyyy');
stock_prices = get_info_from_database('security', 'sec_id', stock_id,...
    'from', from_date, 'to', to_date);

[val idx_stock_dates idx_ret_dates] = intersect(stock_prices(:,1),all_dates_buy_num);

stock_dates_b = stock_prices(idx_stock_dates,1);
stock_prices_ret_b = stock_prices(idx_stock_dates,6);

[val idx_stock_dates idx_ret_dates] = intersect(stock_prices(:,1),all_dates_sell_num);
stock_dates_s = stock_prices(idx_stock_dates,1);
stock_prices_ret_s = stock_prices(idx_stock_dates,6);

all_dates_ret_num_b = datenum(all_dates_ret(1:2:end), 'yyyy-mm-dd');
all_dates_ret_num_s = datenum(all_dates_ret(2:2:end), 'yyyy-mm-dd');

idx_buy = trades(find(trades(:,1) == 1),2);
idx_sell = trades(find(trades(:,1) == -1),2);

% For h2
all_ret_predicted_dup = NaN(2*size(all_ret_predicted,1),1);
all_ret_predicted_dup(1:2:end) = all_ret_predicted;
all_ret_predicted_dup(2:2:end) = all_ret_predicted;

all_ret_real_dup = NaN(2*size(all_ret_predicted,1),1);
all_ret_real_dup(1:2:end) = all_ret_real;
all_ret_real_dup(2:2:end) = all_ret_real;

% For h3
all_dates_p_l_num = NaN(size(cumu_p_l),1);
all_dates_p_l_num(1) = stock_prices(1,1);
all_dates_p_l_num(2:end) = all_dates_ret_num_s(idx_sell);

end